from flaskApp import app
from flask import request
from flask import render_template
from flask import make_response

@app.route("/api/hello/actionX")
def ControllerApiHelloActionX():
    return {
        "code": 0,
        "data": {"f1":1, "f2":2}
    }


@app.route("/api/hello/actionModel")
def ControllerApiHelloActionModel():
    from model.hello import Hello
    dictData = Hello().method1()
    return dictData


@app.route("/api/hello/actionDbInsert")
def ControllerApiHelloActionDbInsert():
    """
    测试链接:   http://127.0.0.1:5000/api/hello/actionDbInsert?name=xiaoming&passwd=123
    """
    uname = request.values.get('name', 'default-name')
    passwd = request.values.get('passwd', 'default-passwd')
    from model.helloDb import HelloDb
    user = {'name': uname, 'passwd': passwd}
    res = HelloDb().insertOneUser(user)
    ret = {'code': 0, 'data': res}
    return ret


@app.route("/api/hello/actionDbQuery")
def ControllerApiHelloActionDbQuery():
    """
    测试链接:   http://127.0.0.1:5000/api/hello/actionDbQuery?name=xiaoming
    """
    name = request.values.get('name', 'default-name')
    from model.helloDb import HelloDb
    res = HelloDb().queryUserByName(name)
    ret = {'code': 0, 'data': res}
    return ret